From: Ian Campbell Date: Wed, 1 Jun 2011 15:46:28 +0000 (+0100) Subject: hvmloader: Add a simple "scratch allocator" X-Git-Tag: archive/raspbian/4.8.0-1+rpi1~1^2~10249 X-Git-Url: https://dgit.raspbian.org/%22http:/www.example.com/cgi/%22https://%22%22/%22http:/www.example.com/cgi/%22https:/%22%22?a=commitdiff_plain;h=80766862aa1c3929c90b27fe3d1850071de9ce98;p=xen.git hvmloader: Add a simple "scratch allocator" Returns memory which is passed to the subsequent BIOS but can be reused once the contents is consumed. An example of this would be a BIOS table which the BIOS consumes by copying rather than simply referencing. Users which need a temporary scratch buffer for internal use scratch_start which follows these allocations. Signed-off-by: Ian Campbell --- diff --git a/tools/firmware/hvmloader/config.h b/tools/firmware/hvmloader/config.h index bc6d445fa1..afce05bbb1 100644 --- a/tools/firmware/hvmloader/config.h +++ b/tools/firmware/hvmloader/config.h @@ -62,6 +62,8 @@ extern unsigned long pci_mem_start, pci_mem_end; #define VGABIOS_PHYSICAL_ADDRESS 0x000C0000 #define HVMLOADER_PHYSICAL_ADDRESS 0x00100000 +extern unsigned long scratch_start; + #endif /* __HVMLOADER_CONFIG_H__ */ /* diff --git a/tools/firmware/hvmloader/hvmloader.c b/tools/firmware/hvmloader/hvmloader.c index 1ba1f37c7f..89407964e7 100644 --- a/tools/firmware/hvmloader/hvmloader.c +++ b/tools/firmware/hvmloader/hvmloader.c @@ -110,6 +110,8 @@ asm ( " .text \n" ); +unsigned long scratch_start = SCRATCH_PHYSICAL_ADDRESS; + static void init_hypercalls(void) { uint32_t eax, ebx, ecx, edx; @@ -481,6 +483,9 @@ int main(void) cmos_write_memory_size(); printf("BIOS map:\n"); + if ( SCRATCH_PHYSICAL_ADDRESS != scratch_start ) + printf(" %05x-%05lx: Scratch space\n", + SCRATCH_PHYSICAL_ADDRESS, scratch_start); if ( vgabios_sz ) printf(" %05x-%05x: VGA BIOS\n", VGABIOS_PHYSICAL_ADDRESS, diff --git a/tools/firmware/hvmloader/pci.c b/tools/firmware/hvmloader/pci.c index 2d7243f14d..61d60c6586 100644 --- a/tools/firmware/hvmloader/pci.c +++ b/tools/firmware/hvmloader/pci.c @@ -48,7 +48,7 @@ void pci_setup(void) /* Create a list of device BARs in descending order of size. */ struct bars { uint32_t devfn, bar_reg, bar_sz; - } *bars = (struct bars *)SCRATCH_PHYSICAL_ADDRESS; + } *bars = (struct bars *)scratch_start; unsigned int i, nr_bars = 0; /* Program PCI-ISA bridge with appropriate link routes. */ diff --git a/tools/firmware/hvmloader/rombios.c b/tools/firmware/hvmloader/rombios.c index 376e4136b0..b4006263af 100644 --- a/tools/firmware/hvmloader/rombios.c +++ b/tools/firmware/hvmloader/rombios.c @@ -138,7 +138,7 @@ static void rombios_create_mp_tables(void) static void rombios_create_smbios_tables(void) { - hvm_write_smbios_tables(SCRATCH_PHYSICAL_ADDRESS, + hvm_write_smbios_tables(scratch_start, SMBIOS_PHYSICAL_ADDRESS, SMBIOS_PHYSICAL_END); } diff --git a/tools/firmware/hvmloader/util.c b/tools/firmware/hvmloader/util.c index d16b4b2fd9..4d80845fc7 100644 --- a/tools/firmware/hvmloader/util.c +++ b/tools/firmware/hvmloader/util.c @@ -362,6 +362,24 @@ void *mem_alloc(uint32_t size, uint32_t align) return (void *)(unsigned long)s; } +void *scratch_alloc(uint32_t size, uint32_t align) +{ + uint32_t s, e; + + /* Align to at least one kilobyte. */ + if ( align < 1024 ) + align = 1024; + + s = (scratch_start + align - 1) & ~(align - 1); + e = s + size - 1; + + BUG_ON(e < s); + + scratch_start = e; + + return (void *)(unsigned long)s; +} + uint32_t ioapic_read(uint32_t reg) { *(volatile uint32_t *)(IOAPIC_BASE_ADDRESS + 0x00) = reg; diff --git a/tools/firmware/hvmloader/util.h b/tools/firmware/hvmloader/util.h index c08715d59a..a9bf47b46e 100644 --- a/tools/firmware/hvmloader/util.h +++ b/tools/firmware/hvmloader/util.h @@ -168,6 +168,9 @@ int vprintf(const char *fmt, va_list ap); void *mem_alloc(uint32_t size, uint32_t align); #define virt_to_phys(v) ((unsigned long)(v)) +/* Allocate memory in a scratch region */ +void *scratch_alloc(uint32_t size, uint32_t align); + /* Connect our xenbus client to the backend. * Call once, before any other xenbus actions. */ void xenbus_setup(void);